@extends('admin.common.base-master')

@section('html-head')

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <em></em>
            @if($type == 'environmental')
                <a href="#">环保知识</a>
            @elseif($type == 'news')
                <a href="#">新闻管理</a>
            @elseif($type == 'about_us')
                <a href="#">关于我们</a>
            @elseif($type == 'join')
                <a href="#">人力资源</a>
            @elseif($type == 'en_environmental')
                <a href="#">环保知识</a>
            @elseif($type == 'en_news')
                <a href="#">新闻管理</a>
            @elseif($type == 'en_about_us')
                <a href="#">关于我们</a>
            @elseif($type == 'en_join')
                <a href="#">人力资源</a>
            @endif
        </div>

        <!--二级目录-->
        @if($type == 'environmental')
            @include('admin.common.news-header')
        @elseif($type == 'news')
            @include('admin.common.news-header')
        @elseif($type == 'about_us')
            @include('admin.common.about-us-header')
        @elseif($type == 'join')
            @include('admin.common.human-res-header')
        @elseif($type == 'en_environmental')
            @include('admin.common.news-header')
        @elseif($type == 'en_news')
            @include('admin.common.news-header')
        @elseif($type == 'en_about_us')
            @include('admin.common.about-us-header')
        @elseif($type == 'en_join')
            @include('admin.common.human-res-header')
        @endif

        <div class="filter-box clearfix">
            <div class="fr">
                <a class="addBtn" href="javascript:;" onclick="upPop(0,'','','edit')">新增</a>
            </div>
        </div>

        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>分类名称</th>
                    <th>链接</th>
                    <th>分类排序</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($allClassifies) > 0)
                    @foreach($allClassifies as $key=>$classify)
                        <tr id="classify_{{$classify->id}}">
                            <td>{{$classify->id}}</td>
                            <td>
                                <span id="classify_name_{{$classify->id}}">{{$classify->name}}</span>
                            </td>
                            <td><a href="javascript:void(0);" data-id="" style="color: #ef1414;" onclick="upPop('{{$classify->link_url}}','{{$classify->title}}','','link')">查看链接</a>
                            <td>{{$classify->sort}}</td>
                            <td>
                                <a href="javascript:void(0);" data-id="{{$classify->id}}" style="color: #ef1414;" onclick="upPop('{{$classify->id}}','{{$classify->name}}','{{$classify->sort}}','edit')">编辑</a> |
                                <a href="javascript:void(0);" class="del" data-id="{{$classify->id}}" >删除</a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
    </div>

    <div class="upPop-box">
        <div class="backdrop"></div>
        <div id="upPop" class="info-pop tixian">
            <input type="hidden" name="id" id="classifyid" value=""/>
            <a class="close" href="javascript:void(0);"></a>
            <h3 id="title"></h3>
            <div class="fill-list" id="link_url">
                <h4 id="url"></h4>
            </div>
            <div class="fill-list" id="classify_name">
                <span class="fill-tit">分类名：</span>
                <input class="fill-ipt" type="text" name="name" id="name" value="">
            </div>

            <div class="fill-list" id="classify_sort">
                <span class="fill-tit">分类排序:</span>
                <input class="fill-ipt" type="text" name="sort" id="sort" value="">
            </div>

            <input type="hidden" name="type" id="type" value="{{$type}}"/>
            <div class="fill-list" id="classify_submit">
                <span class="fill-tit">&nbsp;</span>
                <input class="fill-submit" type="button" id="subThisForm" value="提交">
            </div>
        </div>
    </div>

    <script>
        function upPop(obj1,obj2,obj3,obj4){
            if(obj4 == 'link'){
                $('#classify_name').hide();
                $('#classify_sort').hide();
                $('#classify_submit').hide();
                $('#link_url').show();


                $("#url").html(obj1);
                $("#title").html("链接");
            }else{
                $('#classify_name').show();
                $('#classify_sort').show();
                $('#classify_submit').show();
                $('#link_url').hide();

                $("#title").html("分类设置");
                $('#classifyid').val(obj1);
                $('#name').val(obj2);
                $('#sort').val(obj3);
            }

            $('.upPop-box').upPop();
        }

        $(function(){
            $(document).on('click', '#subThisForm', function () {
                var name  = $('#name').val();
                var sort  = $('#sort').val();
                var type  = $('#type').val();
                var id    = $('#classifyid').val();

                $.ajax({
                    url: '{{route("Api.Admin.sys.addAllClassify")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        name:name,
                        sort:sort,
                        type:type,
                        id:id
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.reload();
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");
                noty({
                    text: '可能影响分类内容，你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                                $noty.close();
                                $.ajax({
                                    url:'{{route('Api.Admin.sys.delAllClassify')}}',
                                    type:'post',
                                    dataType:'json',
                                    data:{id:id},
                                    success:function(obj){
                                        if(obj.level == "success"){
                                            $("#classify_"+id).hide('slow');
                                        }else{
                                            noty({type:obj.level,text:obj.message,timeout:600});
                                        }
                                    },
                                    error:function(obj){
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });

            });
        });
    </script>
@endsection